<?php
namespace App\service;
use EasySwoole\EasySwoole\Config;
use App\service\MyQueue;
use EasySwoole\Component\Process\AbstractProcess;
use EasySwoole\Queue\Job;
use App\Models\UserModel;
use App\Models\Assign;
use App\Models\Project;
class Exptser{



    static function selectexpt($item){
        $cash_trigger = Config::getInstance()->getConf('CASH_TRIGGER');


        $already = Assign::create()->where(['itemid'=>$item['id'],'status'=>[[1,0],'in']])->all();

        if($already){
            var_dump("assign alreay........before");
            return false;
        }

        if($item['cash'] < $cash_trigger){

            //assign jigou expert
            $expert_jg = UserModel::create()->all(['type'=>5,'approve_level'=>$item['type']]);
            
            

            if($expert_jg){

                $expert_jg_selected = $expert_jg[array_rand($expert_jg)]; 

                if($expert_jg_selected){

                    $data = ['assign_eid'=>$expert_jg_selected['id'],'issysttem'=>1,'assgin_displayname'=>$expert_jg_selected['displayname'],'addtime'=>time(),'status'=>0,'itemid'=>$item['id']];
                    Assign::create($data)->save();
                    var_dump("assign ok for item");


                }

            }
        }else{
            //...

            $expts = UserModel::create()->all(['type'=>4,'approve_level'=>$item['type']]);
            $suggest = array_rand($expts,3);
            $group = $suggest[array_rand($suggest,1)];
         
            
            $member = array_diff($suggest,[$group]);




            var_dump($member);

            var_dump($group);
            if($group>=0 && $member){
                $data = ['isgroupleader'=>1,'assign_eid'=>$expts[$group]['id'],'issysttem'=>1,'assgin_displayname'=>$expts[$group]['displayname'],'addtime'=>time(),'status'=>0,'itemid'=>$item['id']];
                Assign::create($data)->save();
                foreach($member as $v){
                    $data = ['assign_eid'=>$expts[$v]['id'],'issysttem'=>1,'assgin_displayname'=>$expts[$v]['displayname'],'addtime'=>time(),'status'=>0,'itemid'=>$item['id']];
                    Assign::create($data)->save();
                }
                var_dump("assign ok for item");
            }

        }


    }












}